widget-factory: Unset needs-attention too
authorMatthias Clasen <mclasen@redhat.com>
Fri, 4 Jul 2014 20:27:11 +0000 (16:27 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 4 Jul 2014 20:27:11 +0000 (16:27 -0400)
This is not done automatically, so unset needs-attention when
the page becomes current.

demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index 041b0b2401d384de94f76ff038b9abf0f87bc2de..121fb9f1178d9292bb52101026f799f52d2657bf 100644 (file)
@@ -283,15 +283,24 @@ close_dialog (GtkWidget *dialog)
   gtk_widget_hide (dialog);
 }
 
-static gboolean
-demand_attention (gpointer page)
+static void
+set_needs_attention (GtkWidget *page, gboolean needs_attention)
 {
   GtkWidget *stack;
 
   stack = gtk_widget_get_parent (page);
   gtk_container_child_set (GTK_CONTAINER (stack), page,
-                           "needs-attention", TRUE,
+                           "needs-attention", needs_attention,
                            NULL);
+}
+
+static gboolean
+demand_attention (gpointer stack)
+{
+  GtkWidget *page;
+
+  page = gtk_stack_get_child_by_name (GTK_STACK (stack), "page3");
+  set_needs_attention (page, TRUE);
 
   return G_SOURCE_REMOVE;
 }
@@ -302,13 +311,27 @@ action_dialog_button_clicked (GtkButton *button, GtkWidget *page)
   g_timeout_add (1000, demand_attention, page);
 }
 
+static void
+page_changed_cb (GtkWidget *stack, GParamSpec *pspec, gpointer data)
+{
+  const gchar *name;
+  GtkWidget *page;
+
+  name = gtk_stack_get_visible_child_name (GTK_STACK (stack));
+  if (g_str_equal (name, "page3"))
+    {
+      page = gtk_stack_get_visible_child (GTK_STACK (stack));
+      set_needs_attention (GTK_WIDGET (page), FALSE);
+    }
+}
+
 static void
 activate (GApplication *app)
 {
   GtkBuilder *builder;
   GtkWindow *window;
   GtkWidget *widget;
-  GtkWidget *page;
+  GtkWidget *stack;
   GtkWidget *dialog;
   GtkAdjustment *adj;
   static GActionEntry win_entries[] = {
@@ -377,8 +400,9 @@ activate (GApplication *app)
   g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
 
   widget = (GtkWidget *)gtk_builder_get_object (builder, "act_action_dialog");
-  page = (GtkWidget *)gtk_builder_get_object (builder, "page3_content");
-  g_signal_connect (widget, "clicked", G_CALLBACK (action_dialog_button_clicked), page);
+  stack = (GtkWidget *)gtk_builder_get_object (builder, "toplevel_stack");
+  g_signal_connect (widget, "clicked", G_CALLBACK (action_dialog_button_clicked), stack);
+  g_signal_connect (stack, "notify::visible-child-name", G_CALLBACK (page_changed_cb), NULL);
 
   dialog = (GtkWidget *)gtk_builder_get_object (builder, "preference_dialog");
   g_signal_connect (dialog, "response", G_CALLBACK (close_dialog), NULL);
index 13a3d43b84b83d035aed8b110c4879fbdcbdf458..b0f19177b8798a458617013dd7020eba830c0313 100644 (file)
@@ -2727,7 +2727,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
               </packing>
             </child>
             <child>
-              <object class="GtkSpinner" id="page3_content">
+              <object class="GtkSpinner">
                 <property name="visible">True</property>
                 <property name="active">True</property>
                 <property name="expand">True</property>